﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysSmsPushLogVMs
{
    public partial class SysSmsPushLogListVM : BasePagedListVM<SysSmsPushLog_View, SysSmsPushLogSearcher>
    {

        protected override IEnumerable<IGridColumn<SysSmsPushLog_View>> InitGridHeader()
        {
            return new List<GridColumn<SysSmsPushLog_View>>{
                this.MakeGridHeader(x => x.Phone),
                this.MakeGridHeader(x => x.Context),
                this.MakeGridHeader(x => x.State),
                this.MakeGridHeader(x => x.Message),
                this.MakeGridHeader(x => x.Name_view),
                this.MakeGridHeader(x => x.PushTime),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysSmsPushLog_View> GetSearchQuery()
        {
            var query = DC.Set<SysSmsPushLog>()
                .CheckContain(Searcher.Phone, x=>x.Phone)
                .CheckContain(Searcher.Context, x=>x.Context)
                .CheckEqual(Searcher.State, x=>x.State)
                .CheckContain(Searcher.Message, x=>x.Message)
                .CheckEqual(Searcher.CreateById, x=>x.CreateById)
                .CheckBetween(Searcher.PushTime?.GetStartTime(), Searcher.PushTime?.GetEndTime(), x => x.PushTime, includeMax: false)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .Select(x => new SysSmsPushLog_View
                {
				    ID = x.ID,
                    Phone = x.Phone,
                    Context = x.Context,
                    State = x.State,
                    Message = x.Message,
                    Name_view = x.CreateBy.Name,
                    PushTime = x.PushTime,
                    CreateTime = x.CreateTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysSmsPushLog_View : SysSmsPushLog{
        [Display(Name = "_Admin.Name")]
        public String Name_view { get; set; }

    }
}
